/***********************************************************************
 * 	Copyright @ 2011 Zhejiang Yutian Technology Co.,Ltd
	==================================================================
	Project:        IMSClient
	FileName:       WeakReferenceHandler.java
	Describtion:    文件描述
	Author:         xufei
	Create Date:    2014-5-6 下午2:17:40
 *********************************************************************/
package com.jason.platform.supervision.base;

import java.lang.ref.WeakReference;
import android.os.Handler;
import android.os.Message;

/**
 * Handler模板类,所有的Handler都必须继承实现,这样可以防止在Activity或者Fragment中传入context造成的内存泄露
 * @author xufei
 * @date 2014-5-6 下午2:17:40
 * @copyright YTXT
 * @version 1.0
 */
public abstract class WeakReferenceHandler<T> extends Handler{

	/** 外部弱引用*/
	protected WeakReference<T> mReference;
	
	public WeakReferenceHandler(T reference){
		mReference = new WeakReference<T>(reference);
	}

	@Override
	public void handleMessage(Message msg) {
		if (mReference.get() == null){
			return;
		}
		handleMessage(mReference.get(), msg);
	}
	
	protected abstract void handleMessage(T reference, Message msg);
	
}
